<?php
/**
 * 功能: 精品
 * User: WD
 * Date: 2018/10/27 0027
 * Time: 16:14
 */

namespace app\admin\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Quality extends Command{
    protected function configure()
    {
        $this->setName('quality')->setDescription('精品商品');
    }

    protected function execute(Input $input, Output $output){
        $output->writeln("精品商品:");
        /*用不超时*/
        ini_set('max_execution_time', 0);
        $this->index();

    }
    public function index(){
        $res = Db::name('icon')->where('is_goods',1)->select();

        if($res){
            $q =  Db::name('goods')->where('is_choice',1)->update(['is_choice'=>2]);
            if($q){
                foreach($res as $k=>$v){
                    Db::name('goods')
                        ->where('gb_id',$v['id'])
                        ->where('member_yongjin','>=',1)
                        ->where('coupon_amount','>=',1)
                        ->order('goods_volume desc')
                        ->limit(100)
                        ->update(['is_choice'=>1]);
                $res =  Db::name('goods')
                        ->where('gb_id',$v['id'])
                        ->where('member_yongjin','>=',1)
                        ->where('coupon_amount','>=',1)
                        ->order('goods_volume desc')
                        ->limit(100)
                        ->count();
                if($res<100){
                    Db::name('goods')
                        ->where('gb_id',$v['id'])
                        ->where('member_yongjin|coupon_amount','>=',1)
                        ->order('goods_volume desc')
                        ->limit(100)
                        ->update(['is_choice'=>1]);
                    $res2 =  Db::name('goods')
                        ->where('gb_id',$v['id'])
                        ->where('member_yongjin|coupon_amount','>=',1)
                        ->order('goods_volume desc')
                        ->limit(100)
                        ->count();
                    if($res2<100){
                        $res3 =  Db::name('goods')
                            ->where('gb_id',$v['id'])
                            ->where('goods_price','<=',50)
                            ->order('goods_volume desc')
                            ->limit(100)
                            ->update(['is_choice'=>1]);
                    }


                }

                }
            }

        }

    }
}